# 导包
import pytest

from api.member_service_api import MemberServiceApi
from data.health_data import find_data, add_data, count_data


class TestMemberService:
    def setup(self):
        # 实例化MemberServiceApi类
        self.ms = MemberServiceApi()

    @pytest.mark.parametrize("p", find_data)
    def test_find_by_tel(self, p):
        # 通过调用封装好的接口层的类以及类里面的方法来获取响应
        tel = p["tel"]
        res = self.ms.find_by_tel(tel)

        # 断言
        if res is None:
            assert res == p["exp"]
        else:
            assert res["phoneNumber"] == p["exp"]

    @pytest.mark.parametrize("p", add_data)
    def test_add(self, p):
        # 通过调用封装好的接口层的类以及类里面的方法来获取响应
        member = p["member"]
        res = self.ms.add(member)

        # 断言
        assert res == p["exp"]

    @pytest.mark.parametrize("p", count_data)
    def test_count(self, p):
        for i in p:
            months = i
            # 使用实例，调用invoke（服务名、函数名、实参）
            res = self.ms.count(months)
            # 断言
            #assert type(res) == "string"
